using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Oops.Xna.Framework
{
	public class Box
	{
		private VertexPositionNormalTexture[] vertices;

		public Box()
		{
			// Initialize the vertex positions for a box shape.
			Vector3 topLeftFront = new Vector3(-1.0f, 1.0f, 1.0f);
			Vector3 topRightFront = new Vector3(1.0f, 1.0f, 1.0f);
			Vector3 topRightBack = new Vector3(1.0f, 1.0f, -1.0f);
			Vector3 topLeftBack = new Vector3(-1.0f, 1.0f, -1.0f);

			Vector3 bottomLeftFront = new Vector3(-1.0f, -1.0f, 1.0f);
			Vector3 bottomRightFront = new Vector3(1.0f, -1.0f, 1.0f);
			Vector3 bottomRightBack = new Vector3(1.0f, -1.0f, -1.0f);
			Vector3 bottomLeftBack = new Vector3(-1.0f, -1.0f, -1.0f);

			Vector2 topLeftSide = new Vector2(0.0f, 0.0f);
			Vector2 topRightSide = new Vector2(1.0f, 0.0f);
			Vector2 bottomRightSide = new Vector2(1.0f, 1.0f);
			Vector2 bottomLeftSide = new Vector2(0.0f, 1.0f);

			// Initialize the normals for each face of a box.
			Vector3 normalFront = new Vector3(0.0f, 0.0f, 1.0f);
			Vector3 normaBack = new Vector3(0.0f, 0.0f, -1.0f);
			Vector3 normalLeft = new Vector3(-1.0f, 0.0f, 0.0f);
			Vector3 normalRight = new Vector3(1.0f, 0.0f, 0.0f);
			Vector3 normalTop = new Vector3(0.0f, 1.0f, 0.0f);
			Vector3 normalBottom = new Vector3(0.0f, -1.0f, 0.0f);

			// Create the list to hold and manage vertices easier.
			this.vertices = new VertexPositionNormalTexture[36];

			// Top face.
			this.vertices[0] = new VertexPositionNormalTexture(topLeftBack, normalTop, Vector2.Zero);
			this.vertices[1] = new VertexPositionNormalTexture(topRightBack, normalTop, Vector2.UnitX);
			this.vertices[2] = new VertexPositionNormalTexture(topLeftFront, normalTop, Vector2.UnitY);
			this.vertices[3] = new VertexPositionNormalTexture(topRightBack, normalTop, Vector2.UnitX);
			this.vertices[4] = new VertexPositionNormalTexture(topRightFront, normalTop, Vector2.One);
			this.vertices[5] = new VertexPositionNormalTexture(topLeftFront, normalTop, Vector2.UnitY);

			// Bottom face.
			this.vertices[6] = new VertexPositionNormalTexture(bottomRightBack, normalBottom, Vector2.One);
			this.vertices[7] = new VertexPositionNormalTexture(bottomLeftBack, normalBottom, Vector2.UnitY);
			this.vertices[8] = new VertexPositionNormalTexture(bottomLeftFront, normalBottom, Vector2.Zero);
			this.vertices[9] = new VertexPositionNormalTexture(bottomRightFront, normalBottom, Vector2.UnitX);
			this.vertices[10] = new VertexPositionNormalTexture(bottomRightBack, normalBottom, Vector2.One);
			this.vertices[11] = new VertexPositionNormalTexture(bottomLeftFront, normalBottom, Vector2.Zero);

			// Front face.
			this.vertices[12] = new VertexPositionNormalTexture(topRightFront, normalFront, topRightSide);
			this.vertices[13] = new VertexPositionNormalTexture(bottomLeftFront, normalFront, bottomLeftSide);
			this.vertices[14] = new VertexPositionNormalTexture(topLeftFront, normalFront, topLeftSide);
			this.vertices[15] = new VertexPositionNormalTexture(topRightFront, normalFront, topRightSide);
			this.vertices[16] = new VertexPositionNormalTexture(bottomRightFront, normalFront, bottomRightSide);
			this.vertices[17] = new VertexPositionNormalTexture(bottomLeftFront, normalFront, bottomLeftSide);

			// Back face.
			this.vertices[18] = new VertexPositionNormalTexture(bottomLeftBack, normaBack, bottomRightSide);
			this.vertices[19] = new VertexPositionNormalTexture(topRightBack, normaBack, topLeftSide);
			this.vertices[20] = new VertexPositionNormalTexture(topLeftBack, normaBack, topRightSide);
			this.vertices[21] = new VertexPositionNormalTexture(bottomRightBack, normaBack, bottomLeftSide);
			this.vertices[22] = new VertexPositionNormalTexture(topRightBack, normaBack, topLeftSide);
			this.vertices[23] = new VertexPositionNormalTexture(bottomLeftBack, normaBack, bottomRightSide);

			// Left face.
			this.vertices[24] = new VertexPositionNormalTexture(bottomLeftFront, normalLeft, bottomRightSide);
			this.vertices[25] = new VertexPositionNormalTexture(bottomLeftBack, normalLeft, bottomLeftSide);
			this.vertices[26] = new VertexPositionNormalTexture(topLeftFront, normalLeft, topRightSide);
			this.vertices[27] = new VertexPositionNormalTexture(topLeftFront, normalLeft, topRightSide);
			this.vertices[28] = new VertexPositionNormalTexture(bottomLeftBack, normalLeft, bottomLeftSide);
			this.vertices[29] = new VertexPositionNormalTexture(topLeftBack, normalLeft, topLeftSide);

			// Right face.
			this.vertices[30] = new VertexPositionNormalTexture(bottomRightBack, normalRight, bottomRightSide);
			this.vertices[31] = new VertexPositionNormalTexture(bottomRightFront, normalRight, bottomLeftSide);
			this.vertices[32] = new VertexPositionNormalTexture(topRightFront, normalRight, topLeftSide);
			this.vertices[33] = new VertexPositionNormalTexture(bottomRightBack, normalRight, bottomRightSide);
			this.vertices[34] = new VertexPositionNormalTexture(topRightFront, normalRight, topLeftSide);
			this.vertices[35] = new VertexPositionNormalTexture(topRightBack, normalRight, topRightSide);
		}

		public VertexPositionNormalTexture[] Vertices
		{
			get { return this.vertices; }
		}
	}
}
